{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Project: MAC Scheme for Stokes Equations\n",
    "\n",
    "The purpose of this project is to implement the simple and popular MAC scheme for solving Stokes equations in two dimensions. \n",
    "\n",
    "Reference\n",
    "* [Progamming of MAC for Stokes equations](http://math.uci.edu/~chenlong/226/MACcode.pdf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Test Examples\n",
    "\n",
    "* Analytic solution. We use a simple model of colliding flow with\n",
    "analytic solutions to test the code. The domain is $[-1,1]^2$  Compute the data `f` and Dirichlet boundary condition `g_D` for the analytic solution:\n",
    "\n",
    "$$u = 20xy^3; \\quad v = 5x^4 - 5y^4; \\quad p = 60x^2y - 20y^3 + {\\rm constant}.$$\n",
    "\n",
    "* Driven cavity problem. The domain is [-1,1]^2. Stokes equation with zero Dirichlet boundary condition except on the top:\n",
    "\n",
    "$$ \\{ y=1; -1 <= x <= 1 | u = 1, v = 0 \\}.$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 1: Gauss-Seidel smoothing of velocity\n",
    "\n",
    "Given a pressure approximation, relax the momentum equation to update velocity. See [Project: Multigrid Methods](projectMG.html) on the matrix free implemenation of G-S relaxation.\n",
    "\n",
    "Note that the boundary or near boundary dof should be updated diffeently. The stencil should be changed according to different boundary conditions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Step 2: Distributive Gauss-Seidel Smoothing (DGS)\n",
    "\n",
    "1. Gauss-Seidel smoothing of velocity to update `u`;\n",
    "* form the residual for the continuity equation `rp = g-Bu`;\n",
    "* solve the Poisson equation for pressure `Ap*ep = rp` by G-S;\n",
    "* distribute the correction to velocity by `u = u + B'*ep`;\n",
    "* update the pressure by `p = p - Ap*ep`.\n",
    "\n",
    "Every step can be implemented in a matrix-free version; see  [Progamming of MAC for Stokes equations](http://math.uci.edu/~chenlong/226/MACcode.pdf).\n",
    "\n",
    "Use DGS as an iterative method to solve the Stokes equation. The iteration steps could be very large but will converges."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Step 3: Two level method\n",
    "\n",
    "The two level method is\n",
    "\n",
    "1. presmoothing by DGS\n",
    "* form residuals for momentum and continunity equations\n",
    "* restrict the residual to the coarse grid\n",
    "* iterate DGS in the coarse grid till converge\n",
    "* prolongate the correction to the fine grid\n",
    "* postsmoothing by DGS\n",
    "\n",
    "Note: the index map between coarse and fine grids are slightly different for `u,v,p`; see  [Progamming of MAC for Stokes equations](http://math.uci.edu/~chenlong/226/MACcode.pdf).\n",
    "\n",
    "Test your two level methods for different levels. It should convergence in less than 20 steps and indepedent of the number of levels."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Step 4: Vcycle multigrid method\n",
    "\n",
    "Recrusively apply the two-level method to the coarse grid problem\n",
    "in the previous step to get a V-cycle method.\n",
    "\n",
    "* Test the convergence of Vcycle method. Record the iteration steps needed to push the relative residual smaller than a tolerance.\n",
    "\n",
    "* Compute the error between the computed approximation to the exact solution and show the convergence rate in terms of mesh size `h`. "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Matlab",
   "language": "matlab",
   "name": "matlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "help_links": [
    {
     "text": "MetaKernel Magics",
     "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
    }
   ],
   "mimetype": "text/x-matlab",
   "name": "matlab",
   "version": "0.14.3"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "120px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": false,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": true,
   "widenNotebook": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
